<!--项目看板---植被覆盖情况 -->
<template>
  <div>
    <el-card class="box-card">
      <div slot="header">
        <span class="header">植被覆盖情况</span>
      </div>
      <div id="barChart" style="width: 100%;height:300px"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default {
  data() {
    return {

    }
  },
  mounted() {
    setTimeout(() => {
      //页面大小适配
      var chartDom = document.getElementById('barChart');
      let myChart = echarts.init(chartDom);
      const chartObserver = new ResizeObserver(() => {
        myChart.resize();
      });
      chartObserver.observe(chartDom);
      //图表样式
      this.initChart()
    })
  },
  methods: {
    initChart() {
      const ctx = document.getElementById('barChart')
      const chart = echarts.init(ctx)
      let option = {
        dataset: {
          source: [
            ["沙蒿", 50],
            ["柠条", 10],
            ["黄柳", 100],
            ["杨荣", 60],
            ["白桦", 80],
            ["榆树", 90]
          ],
        },
        backgroundColor: "#fff",
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        title: {
          // text: "渐变柱状图",
          top: 0,
          right: "4%",
          textStyle: {
            fontWeight: "bold",
            fontSize: 14,
            color: "#666666",
          },
        },
        grid: {
          left: "8%",
          right: "4%",
          bottom: "10%",
          top: "10%",
        },
        xAxis: {
          type: "category",
          axisLine: {
            lineStyle: {
              color: "#dddddd",
            },
          },
          axisTick: {
            show: false,
            alignWithLabel: true,
            lineStyle: {
              color: "#f3f3f3",
            },
          },
          axisLabel: {
            fontSize: 14,
            textStyle: {
              color: "#666666",
              fontFamily: "Microsoft YaHei",
            },
          },
        },
        yAxis: {
          type: "value",
          min: 0,
          // max: yMax,
          axisLine: {
            show: false,
            lineStyle: {
              color: "#dddddd",
            },
          },
          // data: [1, 2, 3],
          axisTick: {
            show: true,
            alignWithLabel: true,
            lineStyle: {
              color: "#dddddd",
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              type: "dotted",
              color: "#dddddd",
              dashOffset: 2,
            },
          },
          axisLabel: {
            padding: [0, 5, 0, 0],
            fontSize: 14,
            textStyle: {
              color: "#666666",
              fontFamily: "Microsoft YaHei",
            },
          },
        },
        series: [
          {
            type: "bar",
            barWidth: 30,
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#9bd08c",
                  },
                  {
                    offset: 1,
                    color: "#008000",
                  },
                ]),
                barBorderRadius: [4, 4, 0, 0],
              },
            },
          },
        ],
      };
      chart.setOption(option)
    }
  }
}
</script>

<style lang="scss" scoped>
.header {
  color: #11A983;
}
.box-card{
  margin-bottom: 10px;
}
</style>

